﻿namespace TestTool.GUI.Utils
{
    using System;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Xml.Serialization;
    using TestTool.GUI.Data;

    internal class ProfilesManager
    {
        public static string FileName = "profiles.xml";

        public static ProfilesSet Load()
        {
            ProfilesSet set = new ProfilesSet();
            try
            {
                IsolatedStorageFile machineStoreForAssembly = IsolatedStorageFile.GetMachineStoreForAssembly();
                IsolatedStorageFileStream stream = new IsolatedStorageFileStream(FileName, FileMode.Open, machineStoreForAssembly);
                StreamReader textReader = new StreamReader(stream);
                XmlSerializer serializer = new XmlSerializer(typeof(ProfilesSet));
                set = (ProfilesSet) serializer.Deserialize(textReader);
                textReader.Close();
            }
            catch
            {
            }
            return set;
        }

        public static void Save(ProfilesSet profiles)
        {
            IsolatedStorageFile machineStoreForAssembly = IsolatedStorageFile.GetMachineStoreForAssembly();
            IsolatedStorageFileStream stream = new IsolatedStorageFileStream(FileName, FileMode.Create, machineStoreForAssembly);
            StreamWriter writer = new StreamWriter(stream);
            new XmlSerializer(typeof(ProfilesSet)).Serialize((TextWriter) writer, profiles);
            writer.Close();
        }
    }
}

